package com.zhangxin.designmode.designpattern.prototype.v2;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zhangxin
 * @date 2022/5/6
 */
public class Demo {

    private ConcurrentHashMap<String, SearchWord> concurrentKeywords = new ConcurrentHashMap<>();

    public void refresh() {

        HashMap<String, SearchWord> newKeywords = new LinkedHashMap<>();

        // 从数据库中取出所有数据，放入到 newKeywords 中
        List<SearchWord> toBeUpdateSearchWords = getSearchWords();
        assert toBeUpdateSearchWords != null;
        for (SearchWord searchWord : toBeUpdateSearchWords) {
            newKeywords.put(searchWord.getKeyword(), searchWord);
        }
    }

    private List<SearchWord> getSearchWords() {
        // TODO: 从数据库中取出所有的数据
        return null;
    }
}
